Page({
  data: {
    filterPerfume: false,
    filterCocktail: false,
    posts: [
      {
        id: 1,
        user: { avatar: '/images/avatar1.png', name: '小香' },
        type: 'perfume',
        content: '今日心情：喷了爱马仕大地，木质清新，气场全开！',
        images: ['/images/rose.jpg'],
        video: '',
        emoji: '🌳✨',
        liked: false,
        likes: 12,
        comments: [{ user: '调酒师A', text: '这款真的好闻！😍' }],
        collected: false
      },
      {
        id: 2,
        user: { avatar: '/images/avatar2.png', name: '调调' },
        type: 'cocktail',
        content: '自制莫吉托，薄荷和青柠的清爽，夏天的味道！',
        images: [],
        video: '/videos/mojito.mp4',
        emoji: '🍹☀️',
        liked: true,
        likes: 20,
        comments: [],
        collected: true
      },
      {
        id: 3,
        user: { avatar: '/images/avatar3.png', name: '香水控' },
        type: 'perfume',
        content: '迪奥旷野，男友力爆棚，推荐给喜欢清新木香的朋友！',
        images: ['/images/dior.jpg'],
        video: '',
        emoji: '🦌🌲',
        liked: false,
        likes: 8,
        comments: [{ user: '小香', text: '超喜欢这款！' }],
        collected: false
      },
      {
        id: 4,
        user: { avatar: '/images/avatar4.png', name: '酒小白' },
        type: 'cocktail',
        content: '第一次尝试调制Negroni，苦甜交织，超有层次感！',
        images: ['/images/negroni.jpg'],
        video: '',
        emoji: '🍸🍊',
        liked: false,
        likes: 5,
        comments: [],
        collected: false
      },
      {
        id: 5,
        user: { avatar: '/images/avatar5.png', name: '香氛少女' },
        type: 'perfume',
        content: '祖玛珑蓝风铃，清新花果香，少女感满满！',
        images: ['/images/bluebell.jpg'],
        video: '',
        emoji: '💐💙',
        liked: true,
        likes: 18,
        comments: [{ user: '香水控', text: '夏天必备！' }],
        collected: true
      },
      {
        id: 6,
        user: { avatar: '/images/avatar6.png', name: '调酒师B' },
        type: 'cocktail',
        content: '今晚的特调：老式（Old Fashioned），橙皮和威士忌的完美结合。',
        images: ['/images/oldfashioned.jpg'],
        video: '',
        emoji: '🥃🍊',
        liked: false,
        likes: 10,
        comments: [],
        collected: false
      },
      {
        id: 7,
        user: { avatar: '/images/avatar7.png', name: '香水猎人' },
        type: 'perfume',
        content: '潘海利根狐狸，玫瑰与木质的优雅碰撞，太迷人了！',
        images: ['/images/fox.jpg'],
        video: '',
        emoji: '🦊🌹',
        liked: false,
        likes: 7,
        comments: [],
        collected: false
      },
      {
        id: 8,
        user: { avatar: '/images/avatar8.png', name: '鸡尾酒爱好者' },
        type: 'cocktail',
        content: '百利甜+咖啡利口酒，DIY一杯B52，层次分明，入口丝滑！',
        images: ['/images/b52.jpg'],
        video: '',
        emoji: '🍶🔥',
        liked: true,
        likes: 15,
        comments: [{ user: '调调', text: '下次一起喝！' }],
        collected: false
      },
      {
        id: 9,
        user: { avatar: '/images/avatar9.png', name: '香水新手' },
        type: 'perfume',
        content: '入门推荐：CK one，柑橘清新，男女都适合！',
        images: ['/images/ckone.jpg'],
        video: '',
        emoji: '🍋🧴',
        liked: false,
        likes: 6,
        comments: [],
        collected: false
      },
      {
        id: 10,
        user: { avatar: '/images/avatar10.png', name: '夜色微醺' },
        type: 'cocktail',
        content: '夜晚来一杯马天尼，橄榄点缀，仪式感拉满！',
        images: ['/images/martini.jpg'],
        video: '',
        emoji: '🍸🫒',
        liked: false,
        likes: 9,
        comments: [],
        collected: false
      }
    ],
    filteredPosts: [],
    showPublish: false,
    publishType: '',
    publishText: '',
    publishImages: [],
    publishVideo: ''
  },
  onLoad() {
    this.updateFilteredPosts();
  },
  updateFilteredPosts() {
    const { posts, filterPerfume, filterCocktail } = this.data;
    let filtered = posts;
    if (filterPerfume && !filterCocktail) {
      filtered = posts.filter(post => post.type === 'perfume');
    } else if (!filterPerfume && filterCocktail) {
      filtered = posts.filter(post => post.type === 'cocktail');
    }
    this.setData({ filteredPosts: filtered });
  },
  onFilterChange(e) {
    const { type } = e.currentTarget.dataset;
    if (type === 'perfume') {
      this.setData({ filterPerfume: !this.data.filterPerfume }, this.updateFilteredPosts);
    } else if (type === 'cocktail') {
      this.setData({ filterCocktail: !this.data.filterCocktail }, this.updateFilteredPosts);
    }
  },
  onShowPublish() {
    this.setData({ showPublish: true });
  },
  onHidePublish() {
    this.setData({ showPublish: false, publishType: '', publishText: '', publishImages: [], publishVideo: '' });
  },
  onSelectType(e) {
    this.setData({ publishType: e.currentTarget.dataset.type });
  },
  onPublishTextInput(e) {
    this.setData({ publishText: e.detail.value });
  },
  onChooseImage() {
    wx.chooseImage({
      count: 3,
      success: res => {
        this.setData({ publishImages: res.tempFilePaths });
      }
    });
  },
  onChooseVideo() {
    wx.chooseVideo({
      maxDuration: 30,
      success: res => {
        this.setData({ publishVideo: res.tempFilePath });
      }
    });
  },
  onSubmitPublish() {
    if (!this.data.publishType) return wx.showToast({ title: '请选择类型', icon: 'none' });
    // 构造新动态
    const newPost = {
      id: Date.now(),
      user: { avatar: '/images/avatar1.png', name: '我' },
      type: this.data.publishType,
      content: this.data.publishText,
      images: this.data.publishImages,
      video: this.data.publishVideo,
      emoji: this.data.publishType === 'perfume' ? '🌸' : '🍸',
      liked: false,
      likes: 0,
      comments: [],
      collected: false
    };
    const posts = [newPost, ...this.data.posts];
    this.setData({ posts }, this.updateFilteredPosts);
    wx.showToast({ title: '发布成功', icon: 'success' });
    this.onHidePublish();
  },
  onLike(e) {
    const idx = e.currentTarget.dataset.idx;
    const posts = this.data.posts;
    posts[idx].liked = !posts[idx].liked;
    posts[idx].likes += posts[idx].liked ? 1 : -1;
    this.setData({ posts }, this.updateFilteredPosts);
  },
  onCollect(e) {
    const idx = e.currentTarget.dataset.idx;
    const posts = this.data.posts;
    posts[idx].collected = !posts[idx].collected;
    this.setData({ posts }, this.updateFilteredPosts);
  },
  // 评论、发布等功能可后续扩展
}) 